#include "define.h"
#define CONFIGPATH "./device.ini"
/*
//LINUX 下ini文件编写函数
#ifndef WIN32
int GetPrivateProfileString(const char *AppName
	, const char *key
	, const char *defaultvalue
	, char *lpReturnedString
	, const int nSize
	, const char *lpFileName)
{
	bool bFindAppName = false;
	char tem[1000];
	char *ptr;
	FILE *fp;
	char name[150];
	snprintf(name, sizeof(name), "[%s]", AppName);
	strncpy(lpReturnedString,defaultvalue, nSize);
	if( (lpFileName == NULL) || ((fp=fopen(lpFileName,"rt"))==NULL) )// || fgets(tem,len,fp) == NULL)
		return strlen(lpReturnedString);
	while(fgets(tem,sizeof(tem),fp)){
		if(tem[0] == '['){
			bFindAppName = false;
			if(strstr(tem,name)==tem)
				bFindAppName = true;
		}else{
			if(bFindAppName == true){
				unsigned int n =strcspn(tem,"=");
				if((strlen(key) == n) && (strncasecmp(tem,key,n) == 0)){
					strncpy(lpReturnedString, tem+n+1,nSize);
					if( (ptr = strchr(lpReturnedString, '\n')) != NULL)
						*ptr = '\0';
					if( (ptr = strchr(lpReturnedString, '\r')) != NULL)
						*ptr = '\0';
					break;
				}
			}
		}
	}
	fclose(fp);
	return strlen(lpReturnedString);
};

int GetPrivateProfileInt(const char *AppName
	, const char *key
	, int defaultvalue
	, const char *lpFileName)
{
	char sztext[256] = {0};
	GetPrivateProfileString(AppName,key, "30",sztext, 256, lpFileName);
	return atoi( sztext );
};

#endif


int getdevicename(char * name, int len){
	return GetPrivateProfileString("device","name", "device",name, len, CONFIGPATH);
}

int gettracepath( char* path, int len ){
	return GetPrivateProfileString("device","tracepath", "./LOG/",path,len, CONFIGPATH);
}

int getdatapath( char* path, int len ){
	return GetPrivateProfileString("device","datapath", "./DB",path,len, CONFIGPATH);
}

int getkeeptimes(){
	return GetPrivateProfileInt("device","keeptime",30, CONFIGPATH);
}

int getmapname(char* logname, char* devname,int len){
	return GetPrivateProfileString("interface",logname,logname,devname,len,CONFIGPATH);
}


char hex2asc(char* shex){
	int mid = 0;
	int idec = 0;
	size_t nlen = strlen(shex);
	if( nlen > 2 )
		return -1;
	for( size_t i = 0; i< nlen; i++ ){
		if( shex[i] >='0' && shex[i]<='9' ) mid = shex[i]-'0';
		else if( shex[i] >='a' && shex[i]<='f' ) mid = shex[i]-'a'+10;
		else if( shex[i] >='A' && shex[i]<='F' ) mid = shex[i]-'A'+10;
		else
			return -1;
		mid <<= ((nlen-i-1)<<2);
		idec |= mid;
	}
	return (char)idec;
};
*/
